<template>
  <el-card shadow="hover">
    <el-table
        :data="studentList"
        style="width: 90%">
      <el-table-column
          label="学号"
          align="center"
          prop="sid"
          width="180"/>
      <el-table-column
          label="姓名"
          prop="sname"
          align="center"/>
      <el-table-column
          label="性别"
          prop="sex"
          align="center"/>
      <el-table-column
          label="年龄"
          prop="age"
          align="center"/>
      <el-table-column
          label="住址"
          prop="addr"
          align="center"/>

      <el-table-column label="操作" align="center">
        <template slot-scope="scope">
          <el-button
              size="mini"
              @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
          <el-button
              size="mini"
              type="danger"
              @click="handleDelete(scope.$index, scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
  </el-card>

</template>

<script>
export default {
  data() {
    return {
      studentList: []
    }
  },
  created() {
    this.getStudents()
  },
  methods: {
    getStudents() {
      console.log("getStudents...")
      this.$axios.get('/student/list').then(res => {
        this.studentList = res.data
      })
    },
    handleEdit(index, row) {
      console.log(index, row);
    },
    handleDelete(index, row) {
      console.log(index, row);
    }
  }
}
</script>

<style>
.el-table {
  margin: 0 auto;
}
</style>
